$(function () {
    chinese.sSearch = "三方账号搜索";
    var table = $('#userList').DataTable({
        "processing": true,
        "serverSide": true,
        "bSort": false,
        "ajax": {
            "url": "user/getCountData",
            "data": function (d) {
                d.loginNameQuery = d.search.value;
            }
        },
        "aoColumnDefs": [{
                "targets": 0,
                "bSortable": false,
                "searchable": false,
                "className": "text-center",
                "mRender": function (data, type, row) {
                    return '<input type="checkbox" />';
                }
            }, {
                "targets": 1,
                "mRender": function (data, type, row) {
                    return '<a href="user/index/' + row.user.id + '" target="_blank">' + row.user.loginName + '</a>';
                }
            }, {
                "targets": 2,
                "mRender": function (data, type, row) {
                    return row.user.mobile;
                }
            }, {
                "targets": 3,
                "mRender": function (data, type, row) {
                    return row.user.name ? row.user.name : '-';
                }
            }, {
                "targets": 4,
                "mRender": function (data, type, row) {
                    return row.user.idNumber ? row.user.idNumber : '-';
                }
            }, 
            {
                "targets": 5,
                "searchable": false,
                "mRender": function (data, type, row) {
                    var status = row.account===null
                        ?'' 
                        : row.account.usrCustId;
                    return status;
                }
            }, {
                "targets": 6,
                "searchable": false,
                "mRender": function (data, type, row) {
                    return $.number(row.fund.available===null?0:0, 2);
                }
            }, {
                "targets": 7,
                "searchable": false,
                "mRender": function (data, type, row) {
                    var status = row.user.enabled
                        ? '<i class="fa fa-check text-success"></i>正常'
                        : '<i class="fa fa-lock text-danger mr4"></i>冻结';
                    return status;
                }
            }, {
                "targets": 8,
                "searchable": false,
                "visible": false,
                "mRender": function (data, type, row) {
                    return $.format.date(new Date(row.user.registerTime), "yyyy/MM/dd HH:mm");
                }
            }, {
                "targets": 9,
                "searchable": false,
                "bSortable": false,
                "visible": false,
                "mRender": function (data, type, row) {
                    return row.user.lastLoginTime !== null
                        ? $.format.date(new Date(row.user.lastLoginTime), "yyyy/MM/dd HH:mm")
                        : '-';
                }
            }, {
                "targets": 10,
                "searchable": false,
                "bSortable": false,
                "visible": false,
                "mRender": function (data, type, row) {
                    return row.referee !== null
                        ? '<a href="user/index/' + row.referee.id + '" target="_blank">' + row.referee.loginName + '</a>'
                        : '-';
                }
            }, 
            {
                "targets": -1,
                "bSortable": false,
                "searchable": false,
                "mRender": function (data, type, row) {
                    var operations = $("#operationHTML").html().replace(/#id/g, row.user.id).replace(/#loginName/g, row.user.loginName);
                    if (!row.user.enabled) {
                        operations = operations.replace("glyphicons-lock", "glyphicons-unlock").replace("冻结", "激活");
                    }
                    return operations;
                }
            }],
        "order": [[8, "desc"]],
        "oLanguage": chinese,
        "iDisplayLength": 10,
        "aLengthMenu": [
            [10, 25, 50, -1],
            [10, 25, 50, "全部"]
        ],
        "sDom": '<"dt-panelmenu clearfix"l<"pull-right"Tf>r>t<"dt-panelfooter clearfix"ip>',
        "oTableTools": {
            "aButtons": [{
                    "sExtends": "copy",
                    "sButtonText": "复制",
                    "fnComplete": function (nButton, oConfig, oFlash, sFlash) {
                        alert('列表内容已复制到剪贴板');
                    }
                }, {
                    "sExtends": "xls",
                    "sButtonText": "导出为Excel"
                }
            ],
            "sSwfPath": root_path + "/js/plugins/datatables/extensions/TableTools/swf/copy_csv_xls_pdf.swf"
        },
        "fnDrawCallback": function () {
            // 高亮显示搜索内容
            if ($("#userList_filter input").val() !== "") {
                $("#userList").highlight($("#userList_filter input").val());
            }
        }
    });
    });
  